/*
 * @lc app=leetcode.cn id=338 lang=typescript
 *
 * [338] 比特位计数
 */

// @lc code=start
function countBits(n: number): number[] {
    return [...Array(n + 1).keys()].map((i) => {
        let count = 0;
        for (const iterator of i.toString(2)) {
            if (iterator === "1") count++;
        }
        return count;
    });
}
// @lc code=end
